<?php
/**
 * Note: *
 */

namespace App\Caches;

use Illuminate\Support\Facades\Cache;

class ManagerCache
{
    const CACHE_TAG = 'manager';

    /**
     * 获取 OPENID
     * @param string $clientId
     * @param string $channel
     * @return array|mixed
     */
    public static function getOpenid(string $clientId, string $channel)
    {
        return Cache::tags(self::CACHE_TAG)->get($clientId.':'.$channel);
    }

    /**
     * 设置openid
     * @param string $clientId
     * @param string $channel
     * @param string $openid
     * @return bool
     * @throws \Psr\SimpleCache\InvalidArgumentException
     */
    public static function setOpenid(string $clientId, string $channel, string $openid): bool
    {
        return Cache::tags(self::CACHE_TAG)->set($clientId.':'.$channel, $openid, 600);
    }

    /**
     * 删除 OPENID
     * @param string $clientId
     * @param string $channel
     * @return bool
     */
    public static function delOpenid(string $clientId, string $channel): bool
    {
        return Cache::tags(self::CACHE_TAG)->forget($clientId.':'.$channel);
    }
}
